# -*- coding:utf-8 -*-
from fastapi import APIRouter, Request, Depends, Query
from typing import Union
from core.response import tableinfo, success, fail
from core.curd import PageInfo, IDList
from core.request import get_page_info, get_query_param
from app.annotation import RequiresPermissions
from app.service.system import SysParamService
from app.entity.system import CreateSysParam, UpdateSysParam

router = APIRouter()


@router.get('/get')
async def get_one(ids: int = Query(), mService=Depends(SysParamService.instance)):
    """
        获取测试详情
    """
    one = await mService.select_by_id(ids)
    return success('OK', one)


@router.get('/list')
async def lists(req: Request, page=Depends(get_page_info), where=Depends(get_query_param),
                mService=Depends(SysParamService.instance)):
    """
        获取测试列表
    """

    total, rows = await mService.select_page(page, where)
    return tableinfo('OK', total, rows)


@router.post('/add')
async def add(post: CreateSysParam, mService=Depends(SysParamService.instance)):
    """
        添加测试
    """
    one = await mService.insert(post.dict())
    return success('OK', one)


@router.post('/edit')
async def update(post: UpdateSysParam, mService=Depends(SysParamService.instance)):
    """
        编辑测试
    """
    one = await mService.update(post.dict())
    return success('OK', one)


@router.post('/del')
async def remove(ids: IDList, mService=Depends(SysParamService.instance)):
    """
        删除测试
    """
    one = await mService.delete_batch_ids(ids.ids)
    return success('OK')
